package com.qinhao.loveCrowdFunding.service;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.qinhao.loveCrowdFunding.mapper.DetailInformationMapper;
import com.qinhao.loveCrowdFunding.pojo.DescriptionBO;
import com.qinhao.loveCrowdFunding.pojo.DescriptionDTO;
import com.qinhao.loveCrowdFunding.pojo.UpdateDescriptionDTO;
import com.qinhao.loveCrowdFunding.req.DescriptionRequest;
import com.qinhao.loveCrowdFunding.req.UpdateDescriptionRequest;

@Service
public class DescriptionService {
    @Autowired
    private DetailInformationMapper detailInformationMapper;
    public DescriptionDTO getDescriptionBySimpleInformationId(DescriptionRequest descriptionRequest) throws Exception {
        DescriptionDTO descriptionDTO = DescriptionDTO.builder().build();
        DescriptionBO descriptionBO =
                detailInformationMapper.getDescriptionBySimpleInformationId(descriptionRequest);
        if (descriptionBO != null) {
            BeanUtils.copyProperties(descriptionBO, descriptionDTO);
        }
        return descriptionDTO;
    }
    public UpdateDescriptionDTO updateDescriptionBySimpleInformationId(UpdateDescriptionRequest updateDescriptionRequest) throws Exception {
        UpdateDescriptionDTO updateDescriptionDTO = UpdateDescriptionDTO.builder().build();
        detailInformationMapper.updateDescriptionBySimpleInformationId(updateDescriptionRequest);
        updateDescriptionDTO.setId(updateDescriptionRequest.getId());
        return updateDescriptionDTO;
    }

    public void updateStatusToZero(UpdateDescriptionRequest updateDescriptionRequest) {
        detailInformationMapper.updateStatusToZero(updateDescriptionRequest);
    }
}
